package com.fp.system.constants;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by haibiao.zhang on 16/12/21.
 */
public interface CronConstants {

    List<String> SECONDS_SPECIAL = new ArrayList<>(Arrays.asList(",", "-", "*", "/"));

    List<String> MINUTES_SPECIAL = new ArrayList<>(Arrays.asList(",", "-", "*", "/"));

    List<String> HOURS_SPECIAL = new ArrayList<>(Arrays.asList(",", "-", "*", "/"));

    List<String> DAYS_SPECIAL = new ArrayList<>(Arrays.asList(",", "-", "*", "/", "?", "L", "W", "C"));

    List<String> MONTHS_SPECIAL = new ArrayList<>(Arrays.asList(",", "-", "*", "/"));

    List<String> WEEKS_SPECIAL = new ArrayList<>(Arrays.asList(",", "-", "*", "/", "?", "L", "#", "C"));

    List<String> YEARS_SPECIAL = new ArrayList<>(Arrays.asList(",", "-", "*", "/"));

    enum SECONDS {
        S60("60", "*"),;

        public static SECONDS getByCode(String code) {
            for (SECONDS hours : SECONDS.values()) {
                if (hours.getNumericSeconds().equals(code)) {
                    return hours;
                }
            }
            return null;
        }

        SECONDS(String numericSeconds, String strSeconds) {
            this.numericSeconds = numericSeconds;
            this.strSeconds = strSeconds;
        }

        private final String numericSeconds;
        private final String strSeconds;

        public String getNumericSeconds() {
            return numericSeconds;
        }

        public String getStrSeconds() {
            return strSeconds;
        }
    }

    enum MINUTES {
        S60("60", "*"),
        S61("61", "-"),;

        public static MINUTES getByCode(String code) {
            for (MINUTES minutes : MINUTES.values()) {
                if (minutes.getNumericMinutes().equals(code)) {
                    return minutes;
                }
            }
            return null;
        }

        MINUTES(String numericMinutes, String strMinutes) {
            this.numericMinutes = numericMinutes;
            this.strMinutes = strMinutes;
        }

        private final String numericMinutes;
        private final String strMinutes;

        public String getNumericMinutes() {
            return numericMinutes;
        }

        public String getStrMinutes() {
            return strMinutes;
        }
    }

    enum HOURS {
        H24("24", "*"),
        H25("25", "-"),;

        public static HOURS getByCode(String code) {
            for (HOURS hours : HOURS.values()) {
                if (hours.getNumericHours().equals(code)) {
                    return hours;
                }
            }
            return null;
        }

        HOURS(String numericHours, String strHours) {
            this.numericHours = numericHours;
            this.strHours = strHours;
        }

        private final String numericHours;
        private final String strHours;

        public String getNumericHours() {
            return numericHours;
        }

        public String getStrHours() {
            return strHours;
        }
    }

    enum DAY {
        D32("32", "*"),
        D33("33", ","),
        D34("34", "-"),
        D35("35", "L"),//某个月最后几天
        D36("36", "?"),//不关心值为什么，若day或week中设置了L，而day和week不能同时为*，这时就只能设置为?
        ;

        public static DAY getByCode(String code) {
            for (DAY day : DAY.values()) {
                if (day.getNumericDay().equals(code)) {
                    return day;
                }
            }
            return null;
        }

        DAY(String numericDay, String strDay) {
            this.numericDay = numericDay;
            this.strDay = strDay;
        }

        private final String numericDay;
        private final String strDay;

        public String getNumericDay() {
            return numericDay;
        }

        public String getStrDay() {
            return strDay;
        }

    }

    enum MONTH {
        M1("1", "JAN"),
        M2("2", "FEB"),
        M3("3", "MAR"),
        M4("4", "APR"),
        M5("5", "MAY"),
        M6("6", "JUN"),
        M7("7", "JUL"),
        M8("8", "AUG"),
        M9("9", "SEP"),
        M10("10", "OCT"),
        M11("11", "NOV"),
        M12("12", "DEC"),
        M13("13", "*"),
        M14("14", "-"),
        M15("15", ","),;

        public static MONTH getByCode(String code) {
            for (MONTH month : MONTH.values()) {
                if (month.getNumericMonth().equals(code)) {
                    return month;
                }
            }
            return null;
        }

        MONTH(String numericMonth, String strMonth) {
            this.numericMonth = numericMonth;
            this.strMonth = strMonth;
        }

        private final String numericMonth;
        private final String strMonth;

        public String getNumericMonth() {
            return numericMonth;
        }

        public String getStrMonth() {
            return strMonth;
        }

    }

    enum WEEK {
        W1("1", "SUN"),
        W2("2", "MON"),
        W3("3", "TUE"),
        W4("4", "WED"),
        W5("5", "THU"),
        W6("6", "FRI"),
        W7("7", "SAT"),
        W8("8", "*"),
        W9("9", "-"),//某个月周几到周几
        W10("10", ","),//某个月周几,周几...
        W11("11", "#"),//某个月第几个周几
        W12("12", "?"),
        W13("13", "L"),;

        public static WEEK getByCode(String code) {
            for (WEEK week : WEEK.values()) {
                if (week.getNumericWeek().equals(code)) {
                    return week;
                }
            }
            return null;
        }

        WEEK(String numericWeek, String strWeek) {
            this.numericWeek = numericWeek;
            this.strWeek = strWeek;
        }

        private final String numericWeek;
        private final String strWeek;

        public String getNumericWeek() {
            return numericWeek;
        }

        public String getStrWeek() {
            return strWeek;
        }
    }

    enum YEAR {
        Y1("1", "*"),
        Y2("2", "-"),
        Y3("3", ","),;

        public static YEAR getByCode(String code) {
            for (YEAR year : YEAR.values()) {
                if (year.getNumericYear().equals(code)) {
                    return year;
                }
            }
            return null;
        }

        YEAR(String numericYear, String strYear) {
            this.numericYear = numericYear;
            this.strYear = strYear;
        }

        private final String numericYear;
        private final String strYear;

        public String getNumericYear() {
            return numericYear;
        }

        public String getStrYear() {
            return strYear;
        }
    }

    enum STATUS {
        S1("1", "true"),
        S2("2", "false"),
        S3("3", "unknown");

        STATUS(String returnCode, String returnMsg) {
            this.returnCode = returnCode;
            this.returnMsg = returnMsg;
        }

        private final String returnCode;
        private final String returnMsg;

        public String getReturnCode() {
            return returnCode;
        }

        public String getReturnMsg() {
            return returnMsg;
        }
    }

}
